<?php

defined('SYSPATH') or die('Access error!');

class Model_Category extends Model
{

    /**
     *  分类列表
     * @param type $where_sql
     * @return type
     */
    public function get_category_list($where_sql = array())
    {
        $where = '';
        if (Arr::validate_arr($where_sql))
        {
            $where .= " AND ".$this->get_where($where_sql);
        }
        $where .= ' ORDER BY position,id';
        
        $category_list = $this->get_results($where);
        return $category_list;
    }
    
    
    /**
     * 取得某分类的所有子孙分类id
     */
    public function get_all_children($id)
    {
        $this->all_children[] = $id;
        $this->_get_all_children($id);
        return $this->all_children;
    }

    /**
     *  递归调用所有子分类（用于小数据）
     * @param type $id
     */
    private function _get_all_children($id)
    {
        $childs = $this->get_category_list(array('parent_id'=>$id));
        foreach ($childs as $child)
        {
            $this->all_children[] = intval($child['id']);
            $this->_get_all_children($child['id']);
        }
    }

}